package com.tj.collection.db.dao.impl;
import cn.hutool.core.date.DateUtil;
import com.fqgj.common.api.Page;
import com.fqgj.common.base.AbstractBaseMapper;
import com.google.common.collect.Maps;
import com.tj.collection.db.dao.RptModelDataPreDayDao;
import com.tj.collection.db.entity.RptModelDataPreDayEntity;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* User: linqu
* Date: 2023-10-24
* Time: 16:55:09.666
*/

@Repository
public class RptModelDataPreDayDaoImpl extends AbstractBaseMapper<RptModelDataPreDayEntity> implements RptModelDataPreDayDao {

    @Override
    public int removeTodayData() {
        return this.getSqlSession().delete(this.getStatement("removeTodayData"));
    }

    @Override
    public int batchInsertData(List<RptModelDataPreDayEntity> batchData) {
        final HashMap<String, Object> params = Maps.newHashMap();
        params.put("list", batchData);
        return this.getSqlSession().insert(this.getStatement("batchInsertData"), params);
    }

    @Override
    public List<RptModelDataPreDayEntity> listTodayData() {
        return this.getSqlSession().selectList(this.getStatement("listTodayData"));
    }

    @Override
    public int updateModelData(String sql) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("sql", sql);
        return this.getSqlSession().update(this.getStatement("updateModelData"), params);
    }

    @Override
    public List<RptModelDataPreDayEntity> listModelData(String chatterCode, Date startDate, Date endDate, Page page) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("chatterCode", chatterCode);
        if (startDate != null) {
            params.put("startDate", Integer.valueOf(DateUtil.format(startDate, "yyyyMMdd")));
            params.put("endDate", Integer.valueOf(DateUtil.format(endDate, "yyyyMMdd")));
        }
        if (page != null) {
            params.put("page", page);
        }
        return this.getSqlSession().selectList(this.getStatement("listModelData"), params);
    }
}